package com.cn.web.service.impl;

import com.cn.api.ApiResult;
import com.cn.mapper.SysPermissionMapper;
import com.cn.mapper.SysUserPermissionRelationMapper;
import com.cn.pojo.SysPermission;
import com.cn.pojo.SysUserPermissionRelation;
import com.cn.web.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private SysPermissionMapper sysPermissionMapper;

    @Autowired
    private SysUserPermissionRelationMapper sysUserPermissionRelationMapper;
    /**
     * 权限查看
     * @return
     */
    @Override
    public ApiResult permissionQuery() {
        List<SysPermission> sysPermissions = sysPermissionMapper.selectList(null);
        return ApiResult.success(sysPermissions);
    }

    /**
     * 权限分配
     * @return
     */
    @Override
    public ApiResult allotQuery(Integer permission,Integer user) {
        SysUserPermissionRelation sysUserPermissionRelation = new SysUserPermissionRelation();
        sysUserPermissionRelation.setUserId(user);
        sysUserPermissionRelation.setPermissionId(permission);
        sysUserPermissionRelationMapper.insert(sysUserPermissionRelation);
        return ApiResult.success("分配成功");
    }
}
